package com.daveclay.boilermaker.web.spring

import com.daveclay.boilermaker.web.InitParamLookup
import org.springframework.web.context.ServletContextAware
import javax.servlet.ServletContext

class SpringInitParamLookup extends InitParamLookup with ServletContextAware {

    var servletContextOpt:Option[ServletContext] = None

    def getInitParameter(name: String) = {
        servletContextOpt match {
            case servletContext:Some[ServletContext] => servletContext.get.getInitParameter(name)
            case None => throw new IllegalStateException("No ServletContext available yet")
        }
    }

    def setServletContext(servletContext: ServletContext) {
        servletContextOpt = Some(servletContext)
    }
}